<template>
	<view class="container">
		<unicloud-db ref="udb" v-slot:default="{data, pagination, loading, hasMore, error}" :collection="collectionList"
			@error="dberror">
			<view v-if="error">{{error.message}}</view>
			<view v-else-if="data">
				<uni-list>
					<uni-list-item v-for="(item, index) in data" :key="index" showArrow :clickable="true"
						@click="handleItemClick(item._id)">
						<template v-slot:body>
							<view class="content">
								<view class="title">
									{{item.content}}
								</view>
								<view class="row">
									<view class="releasetime">
										<uni-dateformat :date="item.create_date" :threshold="[60000, 3600000]"
											format="yyyy年MM月dd"></uni-dateformat>
									</view>
									<view class="name">
										{{giveName(item)}}
									</view>
								</view>
							</view>
						</template>
					</uni-list-item>
				</uni-list>
			</view>
			<uni-load-more :status="loading?'loading':(hasMore ? 'more' : 'noMore')"></uni-load-more>
		</unicloud-db>


	</view>
</template>

<script>
	import {
		giveName
	} from "@/utils/tools.js"
	const db = uniCloud.database()
	export default {
		data() {
			return {
				collectionList: [
					db.collection("opendb-feedback").orderBy("create_date", "desc").getTemp(),
					db.collection("uni-id-users").field("_id,username,nickname").getTemp()
				],
				loadMore: {
					contentdown: '',
					contentrefresh: '',
					contentnomore: ''
				}
			}
		},
		onLoad() {
			uni.setNavigationBarTitle({
				title: '反馈列表'
			});
		},
		onPullDownRefresh() {
			this.$refs.udb.loadData({
				clear: true
			}, () => {
				uni.stopPullDownRefresh()
			})
		},
		onReachBottom() {
			this.$refs.udb.loadMore()
		},
		methods: {
			giveName,
			handleItemClick(id) {
				uni.navigateTo({
					url: './detail?id=' + id
				})
			},
			dberror() {
				uni.switchTab({
					url: '/pages/my/my'
				})
			},
			fabClick() {
				// 打开新增页面
				uni.navigateTo({
					url: './opendb-feedback',
					events: {
						// 监听新增数据成功后, 刷新当前页面数据
						refreshData: () => {
							this.$refs.udb.loadData({
								clear: true
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.container {
		.content {

			.title {
				// padding-right: 15rpx;
				font-size: 34rpx;
				@include text-omission(1);
			}

			.row {
				display: flex;
				color: #888;
				font-size: 24rpx;

				.releasetime {
					padding-right: 20rpx;
				}

				.name {}
			}
		}
	}
</style>